﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using UI.Helper;
using Repository;

namespace UI.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            var repository = RepositoryManager.CreateInformationRepository();
            var model = repository.GetFirst();
            if (model != null)
            {
                model.ViContact = model.EnAboutUs.Replace("\r\n", "<br/>");
                model.EnContact = model.ViAboutUs.Replace("\r\n", "<br/>");
            }
            return View(model);
        }

        public ActionResult Contact()
        {
            var repository = RepositoryManager.CreateInformationRepository();
            var model = repository.GetFirst();
            if (model != null)
            {
                model.ViContact = model.ViContact.Replace("\r\n", "<br/>");
                model.EnContact = model.EnContact.Replace("\r\n", "<br/>");
            }
            return View(model);
        }

        public void Vietnamese()
        {
            if (Request.Cookies[Constants.ENGLISH] != null)
            {
                Response.Cookies[Constants.ENGLISH].Value = "false";
            }
            Response.Redirect("~/Home");
        }

        public void Enghlish()
        {
            if (Request.Cookies[Constants.ENGLISH] != null)
            {
                Response.Cookies.Add(new HttpCookie(Constants.ENGLISH, "true"));
            }
            else
            {
                Response.Cookies[Constants.ENGLISH].Value = "true";
            }
            Response.Redirect("~/Home");
        }
    }
}
